package ferp.android.views.table.animation;

import android.view.animation.Animation;
import ferp.android.views.CardView;
import ferp.android.views.table.TableView;

/**
 * User: olegs
 * Date: 04/01/2015 22:59
 */
public abstract class AnimationListener implements Animation.AnimationListener
{
  public AnimationListener(TableView table, CardView view)
  {
    this.table = table;
    this.view  = view;
    started = false;
  }

  // Important: on some android versions "start" and "end" event
  //            order may be reversed if TranslateAnimation deltas are 0 or animation time is 0
  public final void onAnimationStart(Animation animation) {onAnimationEvent(animation);}
  public final void onAnimationEnd(Animation animation) {onAnimationEvent(animation);}
  public void onAnimationRepeat(Animation animation) {/* do nothing */}

  protected void onRealAnimationStart(Animation animation) {}
  protected void onRealAnimationEnd(Animation animation) {}

  protected TableView table;
  protected CardView view;
  protected boolean started;

  private void onAnimationEvent(Animation animation)
  {
    if (started)
      onRealAnimationEnd(animation);
    else
    {
      onRealAnimationStart(animation);
      started = true;
    }
  }
}
